package com.geek.log4jcontrol.core;

import java.io.File;
import java.io.IOException;
import java.util.Map;

/**
 * @package com.geek.log4jcontrol.core
 * @description 日志的操作
 * @author Goliath
 * @createTime 2012-8-3 上午09:55:10
 * @modifyTime
 */
@SuppressWarnings("unchecked")
public class LogControler {

	private LogControler() {
	}

	private static LogControler logControler = new LogControler();

	public static LogControler getInstance() {
		return logControler;
	}

	/**
	 * @package com.geek.log4jcontrol.core
	 * @description 获取日志---文件形式
	 * @param configMap 日志获取的具体配置参数
	 * @return 日志文件
	 * @returnType File
	 * @author Goliath
	 * @createTime 2012-8-3 上午10:39:23
	 * @modifyTime
	 */
	public File getLog(Map configMap) {
		return null;
	}

	/**
	 * @package com.geek.log4jcontrol.core
	 * @description 获取日志---日志信息
	 * @param configMap 日志获取的具体配置参数
	 * @return 日志信息
	 * @returnType String
	 * @author Goliath
	 * @createTime 2012-8-9 下午03:28:49
	 * @modifyTime
	 */
	public String getLogStr(Map configMap) {
		String logfilePath = (String) configMap.get("logfilePath");
		String monitorTime = (String) configMap.get("monitorTime");
		String rowNum = (String) configMap.get("rowNum");
		String fileSize = (String) configMap.get("fileSize");

		if (logfilePath.startsWith("/")) {
			logfilePath.substring(1, logfilePath.length());
		}
		if (!"".equals(fileSize) && fileSize != null) {
			long fileSizsL = Long.valueOf(fileSize);
			try {
				return new LogTaker().getLogStrByFileSize(logfilePath, fileSizsL);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		if (!"".equals(monitorTime) && monitorTime != null) {
			return getLogStrByTime(logfilePath, monitorTime);
		}
		if (!"".equals(rowNum) && rowNum != null) {
			long row = Long.valueOf(rowNum);
			try {
				return new LogTaker().getLogStrByRownum(logfilePath, row);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return "";
	}

	private String getLogStrByTime(String logfilePath, String monitorTime) {
		// TODO Auto-generated method stub
		return null;
	}
}
